import pandas as pd
import requests
import os
#下载核查结果通知附件到指定文件夹中
def download_file(url, folder_path):
    local_filename = url.split('/')[-1]
    local_filepath = os.path.join(folder_path, local_filename)

    if not os.path.exists(local_filepath):
        with requests.get(url, stream=True) as r:
            r.raise_for_status()
            with open(local_filepath, 'wb') as f:
                for chunk in r.iter_content(chunk_size=8192):
                    f.write(chunk)
        print(f"Downloaded: {local_filepath}")
    else:
        print(f"File already exists: {local_filepath}")

def main():
    excel_file_path = 'F:\\url.xlsx'  # 替换为你的Excel文件路径
    folder_path = 'F:\\txhcFile'

    if not os.path.exists(folder_path):
        os.makedirs(folder_path)

    df = pd.read_excel(excel_file_path)

    for index, row in df.iterrows():
        file_url = row['FILE_URL']
        download_file(file_url, folder_path)

if __name__ == "__main__":
    main()
